package com.spring.nio.core.event.listener.manage;

import com.spring.nio.core.configuration.NioServerBootstrap;
import com.spring.nio.core.event.listener.ExceptionListener;
import com.spring.nio.core.event.listener.FileHandlerListener;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author: YSFY
 * @date: 2021-03-24 14:31
 * @pacage_name: com.spring.nio.core.event.listener.manage
 * @class_name: ApplicationEventDispatchManager
 * @description: 应用事件分发器
 */
public class ApplicationEventDispatchManager {

    /**
     * 配置应用事件监听器
     * */
    public static void configApplicationEventListener() {
        ClassPathXmlApplicationContext context = NioServerBootstrap.getConfig().getClassPathXmlApplicationContext();
        // 异常事件监听器
        context.addApplicationListener(new ExceptionListener());
        // 文件资源释放监听器
        context.addApplicationListener(new FileHandlerListener());
    }

    public static void publishEvent(ApplicationEvent applicationEvent) {
        NioServerBootstrap.getConfig().getClassPathXmlApplicationContext().publishEvent(applicationEvent);
    }
}
